package com.yuanlp.shoppingmall.home.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yuanlp.shoppingmall.R;
import com.yuanlp.shoppingmall.home.model.ResultBeanData;
import com.yuanlp.shoppingmall.utils.Constants;

import java.util.List;

/**
 * Created by 原立鹏 on 2017/8/29.
 */

public class RecommendAdapter extends BaseAdapter {

    private final Context context;
    private final List<ResultBeanData.ResultBean.RecommendInfoBean> recommend_info;

    public RecommendAdapter(Context context, List<ResultBeanData.ResultBean.RecommendInfoBean> recommend_info) {
        this.context=context;
        this.recommend_info=recommend_info;
    }

    @Override
    public int getCount() {
        return recommend_info.size();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewholder=new ViewHolder();
        if (convertView==null){
            convertView=View.inflate(context, R.layout.item_recommend,null);
            viewholder.iv_recommend= (ImageView) convertView.findViewById(R.id.iv_recommend);
            viewholder.tv_name= (TextView) convertView.findViewById(R.id.tv_name);
            viewholder.tv_price= (TextView) convertView.findViewById(R.id.tv_price);
            convertView.setTag(viewholder);
        }else{
            viewholder= (ViewHolder) convertView.getTag();
        }
        ResultBeanData.ResultBean.RecommendInfoBean recommendInfoBean = recommend_info.get(position);
        Glide.with(context).load(Constants.IMG_URL+recommendInfoBean.getFigure()).into(viewholder.iv_recommend);
        viewholder.tv_name.setText(recommendInfoBean.getName());
        viewholder.tv_price.setText(recommendInfoBean.getCover_price());
        return convertView;
    }

    @Override
    public Object getItem(int position) {
        return recommend_info.get(position);
    }


    @Override
    public long getItemId(int position) {
        return position;
    }

    class ViewHolder {
        TextView tv_name;
        TextView tv_price;
        ImageView iv_recommend;
    }

}
